﻿using Lis.IBLL;
using Lis.Model;
using Lis.WebApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace Lis.WebApp.Controllers
{
    [XfhExceptionHandler]
    public class BookInfoController : ApiController
    {
        public IBookInfoService BookInfoService { get; set; }

        public IBookDetailService BookDetailService { get; set; }

        [HttpGet]
        public ServiceResult<IEnumerable<object>> Title(string value)
        {
            try
            {
                return BookInfoService.GetEntityByName(value);
            }
            catch (Exception ex)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = ex.ToString(),
                    Code = "10010"
                };
            }
        }

        [HttpGet]
        public ServiceResult<IEnumerable<object>> ISBN(string value)
        {
            try
            {
                return BookInfoService.GetEntityByISBN(value);
            }
            catch (Exception ex)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = ex.ToString(),
                    Code = "10010"
                };
            }
        }

        [HttpGet]
        public ServiceResult<IEnumerable<object>> Author(string value)
        {
            try
            {
                return BookInfoService.GetEntityByAuthor(value);
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        }

        [HttpGet]
        public ServiceResult<IEnumerable<object>> Publish(string value)
        {
            try
            {
                var book_list = BookInfoService.GetEntityByPulish(value);
                return book_list;
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        }

        [HttpGet]
        public ServiceResult<IEnumerable<object>> DocNumber(string value)
        {
            try
            {
                return BookDetailService.GetEntityByDocNumber(value);
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        }

        [HttpGet]
        public ServiceResult<IEnumerable<object>> BarCode(string value)
        {
            try
            {
                return BookDetailService.GetEntitiesByBarCode(value);
            }
            catch (Exception)
            {
                return new ServiceResult<IEnumerable<object>>()
                {
                    Success = false,
                    Result = null,
                    Message = "网络异常，请稍后再试",
                    Code = "10010"
                };
            }
        }
    }
}
